package com.besall.allbase.view.activity.chipstoollevel4.protocol.InfoParams;

import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_ALARM_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_CALORIES_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_CAMERA_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_COUNTDOWN_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_DATATIME_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_DISTANCE_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_EMOJI_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_HEARTRATE_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_LOGO_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_PHONEFINDER_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_PROGRESS_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_SLEEP_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_SPORTSTIME_CHECK;
import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.KEY_STEPS_CHECK;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.bes.bessdk.utils.SPHelper;

import bb.lanxing.R;
//import  bb.lanxing.R;



public class ShowBandScreen extends DialogFragment {


    public int logo = 0;
    public int datetime = 0;
    public int steps = 0;
    public int calories = 0;
    public int distance = 0;
    public int sportstime = 0;
    public int progress = 0;
    public int emoji = 0;
    public int alarm = 0;
    public int sleep = 0;
    public int heartrate = 0;
    public int countdown = 0;
    public int camera = 0;
    public int finder = 0;



    private ConfigCallBack mConfigCallback;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.config_bandscreen, container, false);
        initView(view);
        return view;
    }

    public void initView(View view){

        RadioGroup logoFormat = (RadioGroup) view.findViewById(R.id.logo);
        logoFormat.setOnCheckedChangeListener(logoCheckChangeListener);
        RadioGroup datetime = (RadioGroup) view.findViewById(R.id.datetime);
        datetime.setOnCheckedChangeListener(datetimeCheckChangeListener);
        RadioGroup steps = (RadioGroup) view.findViewById(R.id.steps);
        steps.setOnCheckedChangeListener(stepsCheckChangeListener);
        RadioGroup calories = (RadioGroup) view.findViewById(R.id.calories);
        calories.setOnCheckedChangeListener(caloriesCheckChangeListener);
        RadioGroup distance = (RadioGroup) view.findViewById(R.id.distance);
        distance.setOnCheckedChangeListener(distanceCheckChangeListener);
        RadioGroup sportstime = (RadioGroup) view.findViewById(R.id.sportstime);
        sportstime.setOnCheckedChangeListener(sportstimeCheckChangeListener);
        RadioGroup progress = (RadioGroup) view.findViewById(R.id.progress);
        progress.setOnCheckedChangeListener(progressCheckChangeListener);
        RadioGroup emoji = (RadioGroup) view.findViewById(R.id.emoji);
        emoji.setOnCheckedChangeListener(emojiCheckChangeListener);
        RadioGroup alarm = (RadioGroup) view.findViewById(R.id.alarm);
        alarm.setOnCheckedChangeListener(alarmCheckChangeListener);
        RadioGroup sleep = (RadioGroup) view.findViewById(R.id.sleep);
        sleep.setOnCheckedChangeListener(sleepCheckChangeListener);
        RadioGroup heartrate = (RadioGroup) view.findViewById(R.id.heartrate);
        heartrate.setOnCheckedChangeListener(heartrateCheckChangeListener);
        RadioGroup countdown = (RadioGroup) view.findViewById(R.id.countdown);
        countdown.setOnCheckedChangeListener(countdownCheckChangeListener);
        RadioGroup camera = (RadioGroup) view.findViewById(R.id.camera);
        camera.setOnCheckedChangeListener(cameraCheckChangeListener);
        RadioGroup finder = (RadioGroup) view.findViewById(R.id.finder);
        finder.setOnCheckedChangeListener(finderCheckChangeListener);

        view.findViewById(R.id.ok).setOnClickListener(mOkListener);
        view.findViewById(R.id.cancel).setOnClickListener(mCancelListener);

    }

    public boolean saveConfig(){
        SPHelper.putPreference(getActivity(), KEY_LOGO_CHECK, logo);
        SPHelper.putPreference(getActivity(), KEY_DATATIME_CHECK, datetime);
        SPHelper.putPreference(getActivity(), KEY_STEPS_CHECK, steps);
        SPHelper.putPreference(getActivity(), KEY_CALORIES_CHECK, calories);
        SPHelper.putPreference(getActivity(), KEY_DISTANCE_CHECK, distance);
        SPHelper.putPreference(getActivity(), KEY_SPORTSTIME_CHECK, sportstime);
        SPHelper.putPreference(getActivity(), KEY_PROGRESS_CHECK, progress);
        SPHelper.putPreference(getActivity(), KEY_EMOJI_CHECK, emoji);
        SPHelper.putPreference(getActivity(), KEY_ALARM_CHECK, alarm);
        SPHelper.putPreference(getActivity(), KEY_SLEEP_CHECK, sleep);
        SPHelper.putPreference(getActivity(), KEY_HEARTRATE_CHECK, heartrate);
        SPHelper.putPreference(getActivity(), KEY_COUNTDOWN_CHECK, countdown);
        SPHelper.putPreference(getActivity(), KEY_CAMERA_CHECK, camera);
        SPHelper.putPreference(getActivity(), KEY_PHONEFINDER_CHECK, finder);
        return true;
    }

    private final RadioGroup.OnCheckedChangeListener logoCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {


            if(checkedId == R.id.show_1){

                logo = 1;
            }else if(checkedId == R.id.hide_1){

                logo = 0;
            }

/*            switch (checkedId){
                case R.id.show_1:
                    logo = 1;
                    break;
                case R.id.hide_1:
                    logo = 0;
                    break;
            }*/
        }
    };

    private final RadioGroup.OnCheckedChangeListener datetimeCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_2){

                datetime = 1;
            }else if(checkedId == R.id.hide_2){

                datetime = 0;
            }

/*            switch (checkedId){
                case R.id.show_2:
                    datetime = 1;
                    break;
                case R.id.hide_2:
                    datetime = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener stepsCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {



            if(checkedId == R.id.show_3){

                steps = 1;
            }else if(checkedId == R.id.hide_3){

                steps = 0;
            }


   /*         switch (checkedId){


                case R.id.show_3:
                    steps = 1;
                    break;
                case R.id.hide_3:
                    steps = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener caloriesCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {


            if(checkedId == R.id.show_4){

                calories = 1;
            }else if(checkedId == R.id.hide_4){

                calories = 0;
            }

  /*          switch (checkedId){
                case R.id.show_4:
                    calories = 1;
                    break;
                case R.id.hide_4:
                    calories = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener distanceCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_5){

                distance = 1;
            }else if(checkedId == R.id.hide_5){

                distance = 0;
            }


/*            switch (checkedId){
                case R.id.show_5:
                    distance = 1;
                    break;
                case R.id.hide_5:
                    distance = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener sportstimeCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {


            if(checkedId == R.id.show_6){

                sportstime = 1;
            }else if(checkedId == R.id.hide_6){

                sportstime = 0;
            }

/*            switch (checkedId){
                case R.id.show_6:
                    sportstime = 1;
                    break;
                case R.id.hide_6:
                    sportstime = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener progressCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_7){

                progress = 1;
            }else if(checkedId == R.id.hide_7){

                progress = 0;
            }

  /*          switch (checkedId){
                case R.id.show_7:
                    progress = 1;
                    break;
                case R.id.hide_7:
                    progress = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener emojiCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {


            if(checkedId == R.id.show_8){

                emoji = 1;
            }else if(checkedId == R.id.hide_8){

                emoji = 0;
            }

 /*           switch (checkedId){
                case R.id.show_8:
                    emoji = 1;
                    break;
                case R.id.hide_8:
                    emoji = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener alarmCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_9){
                alarm = 1;
            }else if(checkedId == R.id.hide_9){
                alarm = 0;
            }

/*            switch (checkedId){
                case R.id.show_9:
                    alarm = 1;
                    break;
                case R.id.hide_9:
                    alarm = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener sleepCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_10){
                sleep = 1;
            }else if(checkedId == R.id.hide_10){
                sleep = 0;
            }

/*            switch (checkedId){
                case R.id.show_10:
                    sleep = 1;
                    break;
                case R.id.hide_10:
                    sleep = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener heartrateCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_11){
                heartrate = 1;
            }else if(checkedId == R.id.hide_11){
                heartrate = 0;
            }

/*            switch (checkedId){
                case R.id.show_11:
                    heartrate = 1;
                    break;
                case R.id.hide_11:
                    heartrate = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener countdownCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_12){
                countdown = 1;
            }else if(checkedId == R.id.hide_12){
                countdown = 0;
            }

/*            switch (checkedId){
                case R.id.show_12:
                    countdown = 1;
                    break;
                case R.id.hide_12:
                    countdown = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener cameraCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {


            if(checkedId == R.id.show_13){
                camera = 1;
            }else if(checkedId == R.id.hide_13){
                camera = 0;
            }

/*            switch (checkedId){
                case R.id.show_13:
                    camera = 1;
                    break;
                case R.id.hide_13:
                    camera = 0;
                    break;
            }*/
        }
    };
    private final RadioGroup.OnCheckedChangeListener finderCheckChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if(checkedId == R.id.show_14){
                finder = 1;
            }else if(checkedId == R.id.hide_14){
                finder = 0;
            }


/*            switch (checkedId){
                case R.id.show_14:
                    finder = 1;
                    break;
                case R.id.hide_14:
                    finder = 0;
                    break;
            }*/
        }
    };



    public void setConfigCallback(ConfigCallBack configCallback) {
        mConfigCallback = configCallback;
    }

    private final View.OnClickListener mOkListener =new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (saveConfig()){
                dismissAllowingStateLoss();
                if (mConfigCallback != null){
                    mConfigCallback.onConfigOk();
                }
            }
        }
    };

    private final View.OnClickListener mCancelListener =new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismissAllowingStateLoss();
            if (mConfigCallback != null){
                mConfigCallback.onConfigCancel();
            }
        }
    };


    public interface ConfigCallBack {

        void onConfigOk();

        void onConfigCancel();
    }



}
